#include <bits/stdc++.h>
using namespace std;

int solve() {
    int nn;
    cin >> nn;

    int a[nn], c[200001] = {}, r[200001], n = 0;
    for (int i = 0; i < nn; i++) {
        cin >> c[0];
        c[c[0]]++;
    }

    for (int i = 1; i < 200001; i++)
        if (c[i] > 0) {
            a[n] = i;
            r[i] = n;

            cout << "a[" << n << "]=" << i << " have " << c[i] << endl;
            n++;
        }

    int p[n];

    for (int i = n - 1; i >= 0; i--) {
        p[i] = (c[1] > 0 && a[i] != 1) ? 0 : -1;
        for (int k = 2; k <= int(floor(sqrt(a[i]))); k++) {
            if (a[i] % k == 0) {
                if (c[k] > 0)
                    p[i] = max(p[i], r[k]);
                if (c[a[i] / k] > 0)
                    p[i] = max(p[i], r[a[i] / k]);
            }
        }
    }

    cout << "p= ";
    for (int i = 0; i < n; i++)
        cout << p[i] << " ";
    cout << endl;

    int res = 0;
    for (int i = n - 1; i >= 0; i--) {
        int j = i;

        int count = c[a[j]];

        while (p[j] >= 0) {
            j = p[j];
            count += c[a[j]];
        }
        res = max(res, count);
    }

    // cout << "Long " << res << endl;

    return nn - res;
}

int main() {
    int t;
    cin >> t;
    while (t-- > 0)
        cout << solve() << endl;
    return 0;
}